import BatchRequest from "../../../src/table/batch/BatchRequest";
import SerializationResponseMockStrings from "./mock.response.serialization.strings";
import SerializationBatchOperationFactory from "./mock.serialization.batchoperation.factory";
import * as Models from "../../../src/table/generated/artifacts/models";
import toReadableStream from "to-readable-stream";

export default class SerializationObjectForBatchRequestFactory {
  public static GetBatchRequestForQueryWithPartitionandRowKeyResponseMock(): BatchRequest {
    const mockRequest = new BatchRequest(
      SerializationBatchOperationFactory.GetBatchOperationMockForQueryEntityWithPartitionKeyAndRowKey(
        SerializationResponseMockStrings.EmptyHeaderMock
      )
    );
    return mockRequest;
  }

  public static GetBatchRequestForSingleInsertResponseMock(): BatchRequest {
    const mockRequest = new BatchRequest(
      SerializationBatchOperationFactory.GetBatchOperationMockForInsertSingleEntity(
        SerializationResponseMockStrings.EmptyHeaderMock
      )
    );
    return mockRequest;
  }

  public static GetBatchRequestForSingleDeleteResponseMock(): BatchRequest {
    const mockRequest = new BatchRequest(
      SerializationBatchOperationFactory.GetBatchOperationMockForDeleteSingleEntity(
        SerializationResponseMockStrings.EmptyHeaderMock
      )
    );
    return mockRequest;
  }

  // see GetBatchTableQueryEntitiesWithPartitionAndRowKeyResponseMock
  // for a more complete set of response props we can set
  // this mock does not need it
  public static GetBatchOperationMockForSingleInsert() {
    const responseObject = new Object() as Models.TableInsertEntityResponse;
    // Etag in response should be W/\"datetime'2021-02-12T08%3A28%3A27.47468Z'\"
    // prettier-ignore
    responseObject.eTag = 'W/"datetime\'2021-02-12T08%3A28%3A27.47468Z\'"';
    responseObject.statusCode = 204; // no content
    return responseObject as Models.TableInsertEntityResponse;
  }

  public static GetBatchOperationMockForSingleDelete() {
    const responseObject = new Object() as Models.TableDeleteEntityResponse;
    // Etag in response should be W/\"datetime'2021-02-12T08%3A28%3A27.47468Z'\"
    // prettier-ignore
    responseObject.statusCode = 204; // no content
    return responseObject as Models.TableDeleteEntityResponse;
  }

  public static GetBatchTableQueryEntitiesWithPartitionAndRowKeyResponseMock() {
    const responseObject = new Object() as Models.TableQueryEntitiesWithPartitionAndRowKeyResponse;
    // If a client request id header is sent in the request, this header will be present in the
    // response with the same value.
    responseObject.clientRequestId = "";
    // This header uniquely identifies the request that was made and can be used for troubleshooting
    // the request.
    responseObject.requestId = "";
    // Indicates the version of the Table service used to execute the request. This header is
    // returned for requests made against version 2009-09-19 and above.
    responseObject.version = "";
    // UTC date/time value generated by the service that indicates the time at which the response was
    // initiated.
    responseObject.date = new Date();
    // UTC date/time value generated by the service that indicates the time at which the response was
    // initiated
    // code formatter / prettier is messing up the string format which messes the response
    // prettier-ignore
    responseObject.eTag = 'W/"datetime\'2021-02-05T17%3A15%3A16.7935715Z\'"';
    // This header contains the continuation token value for partition key.
    responseObject.xMsContinuationNextPartitionKey = "";
    // This header contains the continuation token value for row key.
    responseObject.xMsContinuationNextRowKey = "";
    responseObject.errorCode = "";
    // using module to-readable-stream
    responseObject.body = toReadableStream(
      '{"odata.metadata":"https://azuritetesttarget.table.core.windows.net/$metadata#TestingAzurite/@Element",\
"odata.etag":"W/"datetime\'2021-02-05T17%3A15%3A16.7935715Z\'"","PartitionKey":"part1","RowKey":"row161254531681303585",\
"Timestamp":"2021-02-05T17:15:16.7935715Z","myValue":"value1"}'
    );
    responseObject.statusCode = 200;

    return responseObject as Models.TableQueryEntitiesWithPartitionAndRowKeyResponse;
  }
}
